﻿using UnityEngine;
namespace TC
{ 
    public abstract class Connection<T0, T1>
    {
        public int id;

        public T0 source;
        public T1 target;

        public Connection(T0 source, T1 target)
        {
            this.source = source;
            this.target = target;
        }
    }

    public class NodeConnection : Connection<Node, Node>
    {
        public NodeConnection(Node source, Node target) : base(source, target)
        {
        }
    }

    public abstract class PortConnection : Connection<Port, Port>
    {
        public PortConnection(Port source, Port target) : base(source, target)
        {
            this.source = source;
            this.target = target;
        }

        public Port GetOther(Port p)
        {
            if (p == source)
                return target;
            else if (p == target)
                return source;
            return null;
        }
    }

    public class FlowConnection : PortConnection
    {
        public FlowConnection(FlowPort source, FlowPort target) : base(source, target) { }
    }

    public class ValueConnection : PortConnection
    {
        public ValueConnection(ValuePort source, ValuePort target) : base(source, target){ }
    }
}
